<?php
/**
 * Created by PhpStorm.
 * User: zk
 * Date: 2018/9/27
 * Time: 下午2:55
 */

namespace app\models;
use yii\db\ActiveRecord;

class Gl_gifttemp extends ActiveRecord {
    //获取礼物列表
    public function getGiftTempList($limit, $offset, $userName) {
        $post = Gl_gifttemp::find();
        if ($userName != -1) {
            $post->andWhere(['like', 'gifttemp_name', $userName]);
        }
        $count = $post->count();
        $result = $post->limit($limit)->offset($offset)->asArray()->all();
        return ['total' => $count, 'rows' => $result];
    }

    //更新礼物资料
    public function updateGiftTemp($giftTempCode, $giftTempName, $giftTempPic, $giftTempPirce, $giftTempRank, $isDeleted) {
        $giftTemp = Gl_gifttemp::findOne(['gifttemp_code' => $giftTempCode]);
        if ($giftTempName != -1)
            $giftTemp->gifttemp_name = $giftTempName;
        if ($giftTempPic != -1)
            $giftTemp->gifttemp_pic = $giftTempPic;
        if ($giftTempPirce != -1)
            $giftTemp->gifttemp_pirce = $giftTempPirce;
        if ($giftTempRank != -1)
            $giftTemp->gifttemp_rank = $giftTempRank;
        if ($isDeleted != -1)
            $giftTemp->is_deleted = $isDeleted;
        $result = $giftTemp->save();
        return $result;
    }

    // 查找礼物编辑的数据
    public function editgiftTemp($gifttemp_code) {
        $result = Gl_gifttemp::find()->where(['gifttemp_code' => $gifttemp_code])->asArray()->one();

        return $result;
    }
}